package futurewonder;

import futurewonder.Components.ComponentsCustomiser;

import futurewonder.Core.ConnectionManager;

import futurewonder.Utilities.Tools;

import futurewonder.hibernation.StoreData;

import java.awt.Dimension;
import java.awt.SystemColor;

import java.awt.event.ActionEvent;

import java.awt.event.ActionListener;

import java.sql.SQLException;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

import oracle.jdeveloper.layout.XYConstraints;
import oracle.jdeveloper.layout.XYLayout;


public class FutureWonder extends JFrame implements ActionListener {

    private JPanel MainPanel = new JPanel();
    private XYLayout xYLayout1 = new XYLayout();
    private XYLayout xYLayout2 = new XYLayout();
    private JLabel lbUname = new JLabel();
    private JLabel lbPassword = new JLabel();
    private JTextField tfUname = new JTextField();
    private JTextField tfPassword = new JTextField();
    private JButton bLogin = new JButton();

    private ComponentsCustomiser cCustomizer = new ComponentsCustomiser();

    public FutureWonder() {
        try {
            jbInit();
            Tools.debug("App started");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private void jbInit() throws Exception {
        this.getContentPane().setLayout(xYLayout2);
        this.setSize(new Dimension(640, 480));

        this.setBackground(SystemColor.window);
        MainPanel.setBackground(SystemColor.window);
        MainPanel.setLayout(xYLayout1);

        cCustomizer.setLabelView(lbUname);
        cCustomizer.setLabelView(lbPassword);
        cCustomizer.setButton(bLogin);

        this.setTitle("FutureWonder");
        lbUname.setText("Username");
        lbPassword.setText("Password");
        bLogin.setText("Login");

        MainPanel.add(bLogin, new XYConstraints(225, 215, 105, 25));
        MainPanel.add(tfPassword, new XYConstraints(225, 155, 240, 20));
        MainPanel.add(tfUname, new XYConstraints(225, 100, 240, 20));
        MainPanel.add(lbPassword, new XYConstraints(15, 155, 155, 20));
        MainPanel.add(lbUname, new XYConstraints(15, 100, 150, 20));
        this.getContentPane().add(MainPanel, new XYConstraints(0, 0, 640, 450));
        this.setVisible(true);
        this.setResizable(false);
        this.setLocationRelativeTo(null);

        bLogin.addActionListener(this);
    }

    public void actionPerformed(ActionEvent ae) {
        if (ae.getSource().equals(bLogin)) {
            String s1 = tfUname.getText();
            String s2 = tfPassword.getText();

            getAccess();
        }
    }

    private void getAccess() {
        
        ConnectionManager cMan = new ConnectionManager();
        cMan.getConnected();
    }

    public static void main(String args[]) {
        //        SwingUtilities.invokeLater(new Runnable(){
        FutureWonder wonder = new FutureWonder();
        //        });
        
    }
}
